package org.opu.pc.ui.client.widgets;

import java.util.Collection;

import org.opu.pc.services.beans.AbstractBean;
import org.opu.pc.services.beans.PublisherBean;
import org.opu.pc.ui.client.BeanView;
import org.opu.pc.ui.client.i18n.PublicationI18N;

public class TableRenderPublisher implements TableRender<PublisherBean> {

	public static final Object[] COLUMN_NAMES;
	public static final Class<?>[] TYPES = new Class<?>[] {
        String.class,
        String.class,
        String.class,
        Boolean.class
    };

    static {
        PublicationI18N i18n = new PublicationI18N();
        COLUMN_NAMES = new Object[]{
                    i18n.get("secondName", "Second name"),
                    i18n.get("name", "Name"),
                    i18n.get("lastName", "Last name"),
                    i18n.get("isStudent", "Student")
                };
    }

	@Override
	public Class<PublisherBean> getRenderingClass() {
		return PublisherBean.class;
	}

	@Override
	public void rendView(Collection<? extends AbstractBean> beans, BeanView view) {
		Object[][] rowData = new Object[beans.size()][4];

		int i = 0;
		for (AbstractBean tb : beans) {
			PublisherBean bean = (PublisherBean) tb;
			rowData[i][0] = bean.getSurname();
			rowData[i][1] = bean.getName();
			rowData[i][2] = bean.getMiddleName();
			rowData[i][3] = bean.isStudent();
			i++;
		}
		view.setContent(COLUMN_NAMES, TYPES, rowData);
	}

}
